package com.eva.baidulibrary;

import android.os.Bundle;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;

import java.util.ArrayList;
import java.util.List;

/**
 * Class description
 *
 * @author GUXIA318
 * @date 2015-09-11 9:41
 */
public class CustomizedOverlay<T extends BaseMarker> extends CustomizedOverlayManager {

    private List<T> list;

    public CustomizedOverlay(BaiduMap baiduMap) {
        super(baiduMap);
    }

    public void setData(List<T> list) {
        this.list = list;
    }

    @Override
    public List<OverlayOptions> getOverlayOptions() {
        if (this.list != null && this.list.size() > 0) {
            ArrayList options = new ArrayList();
            for (int i = 0; i < list.size(); i++) {
                T marker = list.get(i);
                Bundle bundle = new Bundle();
                bundle.putInt("index", i + 1);
                MarkerOptions option = new MarkerOptions();
                option.icon(BitmapDescriptorFactory.fromResource(marker.getMarkerResId()));
                option.extraInfo(bundle);
                option.position(marker.getLatLng());
                options.add(option);
            }
            return options;
        } else {
            return null;
        }
    }

    @Override
    public boolean onMarkerClick(Marker marker) {
        return !this.overlays.contains(marker) ? false : true;
    }

}
